package leecode

func isBalancedLCR(root *TreeNode) bool {
	return getHeightLCR(root) != -1
}

func getHeightLCR(node *TreeNode) int {
	if node == nil {
		return 0
	}
	leftHeight := getHeightLCR(node.Left)
	if leftHeight == -1 {
		return -1
	}
	rightHeight := getHeightLCR(node.Right)
	if rightHeight == -1 {
		return -1
	}
	res := rightHeight - leftHeight
	if Abs(res) > 1 {
		return -1
	}
	return max(leftHeight, rightHeight) + 1
}
